package com.qf.test.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.test.mapper.DtsRegionMapper;
import com.qf.test.pojo.DtsRegion;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RegionServiceImpl implements RegionService{
    @Autowired
    private DtsRegionMapper dtsRegionMapper;
    /**
     * 行政区域
     * 查询所有的数据并返回
     * @return
     */
    @Override
    public IPage<DtsRegion> queryDtsRegion(String name, String code, Integer page, Integer limit) {
        //1.创建分页对象
        //参数1 当前页 第二参数每页显示的条数
        Page<DtsRegion> ipage = new Page<>(page, limit);

        //2.封装查询对象
        QueryWrapper<DtsRegion> queryWrapper = new QueryWrapper<>();

       if(!StringUtils.isEmpty(name)){
           queryWrapper.like("name",name);
       }
       if(!StringUtils.isEmpty(code)){
           queryWrapper.like("code",code);
       }
        Page<DtsRegion> dtsRegionPage = dtsRegionMapper.selectPage(ipage, queryWrapper);
        return dtsRegionPage;
    }
}
